package rohyunji.swing.outline;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.ImageIcon;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JButton;
import javax.swing.JToolBar;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.URL;


/*툴바 작성순서 
 *Jtoolbar 작성 - > 버튼생성 -> 툴바에 추가  
 */
public class J08_HelloSwingToolbar extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					J08_HelloSwingToolbar frame = new J08_HelloSwingToolbar();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public J08_HelloSwingToolbar() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnFilef = new JMenu("File (F)");
		menuBar.add(mnFilef);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		//ToolBar
		JToolBar toolBar = new JToolBar();
		toolBar.setFloatable(false);//툴바이동방지
//		toolBar.setFocusable(false);//클릭시 테두리가 제거됨
		contentPane.add(toolBar, BorderLayout.NORTH);
		
		//툴바 클릭시 이벤트 처리를 담당할 클래스 등록
		J07_HelloSwingActionListener action=new  J07_HelloSwingActionListener();
		
		
		//툴바에 추가할 버튼 추가 
		JButton btnNewButton = new JButton("새로만들기");
		btnNewButton.setFocusPainted(false);
		btnNewButton.addActionListener(action);
		btnNewButton.setActionCommand("new");
		
//		툴바에 표시할 아이콘 이미지 파일 위치 지정
		URL iconURL =getClass().getResource("/images/toolbar/new.png");
//		맨앞슬래쉬는 해당프로젝트 src를 의미,툴바버튼에 이미지지정
		btnNewButton.setIcon(new ImageIcon(iconURL,"새로만들기2"));
//		툴바버튼에 툴팁(용도설명) 추가
		btnNewButton.setToolTipText("new");
		
		toolBar.add(btnNewButton);//툴바에 추가
		
		JButton btnNewButton_1 = new JButton("New button");
		btnNewButton_1.addActionListener(action);
		btnNewButton_1.setActionCommand("Button");
		toolBar.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("New button");
		btnNewButton_2.addActionListener(action);
		btnNewButton_2.setActionCommand("Button");
		toolBar.add(btnNewButton_2);
	}

}
